/*
 * @Author: wangdazhuang
 * @Date: 2025-01-18 09:14:01
 * @LastEditTime: 2025-01-18 09:51:16
 * @LastEditors: wangdazhuang
 * @Description: 
 * @FilePath: /pornhub_app/lib/views/douyin/short_video_player/views/short_video_hots.dart
 */

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/http/api/api.dart';
import 'package:pornhub_app/model/video_base_model.dart';
import 'package:pornhub_app/utils/extension.dart';

import '../../../../generate/app_image_path.dart';
import '../../../../routes/routes.dart';
import '../../../../utils/color.dart';

class ShortVideoHots extends StatefulWidget {
  const ShortVideoHots({super.key});

  @override
  State<StatefulWidget> createState() => _State();
}

class _State extends State<ShortVideoHots> {
  Widget _buildMoreArrow() {
    return Image.asset(
      AppImagePath.short_short_more,
      width: 12.w,
      height: 12.w,
    );
  }

  Widget _buildHotFire() {
    return Image.asset(AppImagePath.short_short_hot_fire,
        width: 17.w, height: 22.w);
  }

  Widget _buildVertialBanner(List<VideoBaseModel> videoList) {
    return SizedBox(
      height: 35.w,
      child: CarouselSlider(
        options: CarouselOptions(
          scrollDirection: Axis.vertical,
          height: 35.w,
          autoPlay: true,
        ),
        items: videoList.map((i) {
          return Builder(
            builder: (BuildContext context) {
              return Text(
                i.title ?? '',
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                style: kTextStyle(COLOR.hexColor('#FEE041'), fontsize: 13.w),
              );
            },
          );
        }).toList(),
      ),
    );
  }

  void _get2RainBowHots() {
    Get.toNamed(Routes.rainbowHot);
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: Future.value(Api.fetchRainBowhots()),
      builder: (context, snapshot) {
        if (snapshot.hasData && snapshot.data != null) {
          List<VideoBaseModel> videoList = snapshot.data!;
          return Positioned(
            left: 0,
            right: 0,
            bottom: 0,
            child: Container(
              width: double.infinity,
              height: 35.w,
              decoration: BoxDecoration(
                color: Colors.black.withOpacity(0.5),
              ),
              child: Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  SizedBox(width: 10.w),
                  _buildHotFire(),
                  SizedBox(width: 10.w),
                  Expanded(child: _buildVertialBanner(videoList)),
                  SizedBox(width: 10.w),
                  _buildMoreArrow(),
                ],
              ).paddingSymmetric(horizontal: 10.w),
            ).onTap(_get2RainBowHots),
          );
        }
        return const SizedBox.shrink();
      },
    );
  }
}
